package thread.multi;

//问题：多线程操作同一个资源下，线程不安全，数据存在紊乱
public class ProblemThread implements Runnable {
    private int ticknums = 10;

    @Override
    public void run() {
        while (true) {
            if (ticknums <= 0) {
                break;
            }
            //模拟延时
            try {
                Thread.sleep(200);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName()
                    +"购买了第"+ticknums--+"张票。");
        }
    }

    public static void main(String[] args) {
        ProblemThread ticks = new ProblemThread();

        new Thread(ticks,"黄牛").start();
        new Thread(ticks,"小明").start();
        new Thread(ticks,"CphRed").start();

    }
}
